package com.vhall.component.controller.chat;


import com.vhall.component.entity.chat.dto.QuickRepliesCreateDTO;
import com.vhall.component.entity.chat.dto.QuickRepliesDTO;
import com.vhall.component.entity.chat.vo.*;
import com.vhall.component.entity.page.vo.PageVO;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.service.chat.QuickRepliesConsoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 快捷回复表 前端控制器 admin(后台管理)相关接口
 *
 * @author xing.wang
 * @since 2022-09-05
 */
@RestController
@RequestMapping("/v4/quick-replies/admin")
@Slf4j
public class QuickRepliesAmdController {
    @Resource(name = "QuickRepliesConsole")
    private QuickRepliesConsoleService quickRepliesService;

    /**
     * [admin]新增快捷回复
     * 1. 创建的时候默认的信息,状态为"禁用",类型为"系统"
     * 2. 创建时限定,快捷回复内容不能超过20字
     * 3. 创建时限定,不能有重复的快捷回复
     * 4. 创建时是admin端的account_id保存为0
     *
     * @param quickRepliesCreateVO 参数
     * @return 创建的快捷回复dto类
     */
    @PostMapping("/create")
    @TokenAuth
    public QuickRepliesCreateDTO create(@Validated QuickRepliesCreateVO quickRepliesCreateVO) {
        return quickRepliesService.create(quickRepliesCreateVO);
    }

    /**
     * [admin]更新快捷回复
     * 1.快捷回复内容不能为空
     * 2.快捷回复内容不能超过20字
     * 3.更新后不能出现重复的快捷回复
     * 4.需要登录后才能做更新
     *
     * @param quickRepliesUpdateVO 参数
     * @return 是否更新成功
     */
    @PostMapping("/update")
    @TokenAuth
    public Boolean update(@Validated QuickRepliesUpdateVO quickRepliesUpdateVO) {
        return quickRepliesService.update(quickRepliesUpdateVO);
    }

    /**
     * [admin]删除快捷回复
     * 1. 删除时必须传递快捷回复ID
     * 2. 必须是登录后才能删除
     *
     * @param quickRepliesDeleteVO 参数
     * @return 是否删除成功
     */
    @PostMapping("/delete")
    @TokenAuth
    public Boolean delete(@Validated QuickRepliesDeleteVO quickRepliesDeleteVO) {
        return quickRepliesService.delete(quickRepliesDeleteVO);
    }

    /**
     * [admin]设置回复状态
     * 1.
     *
     * @param quickRepliesSetStatusVO 参数
     * @return 是否设置成功
     */
    @PostMapping("/set-status")
    @TokenAuth
    public Boolean setStatus(@Validated QuickRepliesSetStatusVO quickRepliesSetStatusVO) {
        return quickRepliesService.setStatus(quickRepliesSetStatusVO);
    }

    /**
     * [admin]获取快捷回复分页列表
     *
     * @param quickRepliesListVO 参数
     * @return 分页的快捷回复列表
     */
    @PostMapping("/list")
    @TokenAuth
    public PageVO<QuickRepliesDTO> list(@Validated QuickRepliesListVO quickRepliesListVO) {
        return quickRepliesService.pageList(quickRepliesListVO);
    }
}


